package com.blb.proxy;

public class ProxyDemo {

    public static void main(String[] args) {
        //创建工厂对象
        CellphoneSales factory = new CellphoneFactory();
//        //创建代理商对象
//        CellphoneSales proxy = new CellphoneProxy(factory);
//        proxy.sell("华为P60");
        ComputerSales computerFactory = new ComputerFactory();
//        ComputerSales computerProxy = new ComputerProxy(computerFactory);
//        computerProxy.sell("苹果电脑");
        JDKFactoryProxy proxy = new JDKFactoryProxy();
        //创建动态代理对象
        CellphoneSales cellphoneSales = (CellphoneSales) proxy.createProxyInstance(factory);
        cellphoneSales.sell("小米13");
        ComputerSales computerSales = (ComputerSales) proxy.createProxyInstance(computerFactory);
        computerSales.sell("戴尔9999");

//        Hello obj = (Hello) proxy.createProxyInstance(new Hello());
//        obj.sell("xxx");

        System.out.println(computerFactory.getClass());
        System.out.println(computerSales.getClass());


        //CGLib动态代理
        CGLibFactoryProxy cglibProxy = new CGLibFactoryProxy();
        CellphoneSales cellProxy = (CellphoneSales) cglibProxy.createProxyInstance(factory);
        cellProxy.sell("华为P99");
        ComputerSales computerProxy = (ComputerSales) cglibProxy.createProxyInstance(computerFactory);
        computerProxy.sell("小米电脑");
        Hello hello = (Hello) cglibProxy.createProxyInstance(new Hello());
        hello.sell("world");
        System.out.println(hello.getClass());
    }
}
